<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>盱眙供电局点位配置</title>
     <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="../../layui256/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <script src="../../layui256/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script src="../../js/jquery-ui-1.10.4.custom.min.js"></script>
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <style>
    .layui-table-tool{
    	z-index:0;
    }
    .layui-table-fixed{
    	z-index:0;
    }
    </style>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                    <div id= "regionChoose">
                     <div class="layui-inline" >
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width:120px">点位名称:</label>
                            <div class="layui-input-block" style="width:180px;margin-left:120px;">
			                    <input type="text" name="regionNameText" id="regionNameText" required lay-verify="required"
			                           placeholder=""
			                           autocomplete="off" class="layui-input">
			                </div>
                        </div>
                    </div>
                        <div class="layui-inline" pane="">
                            <button class="layui-btn layui-btn-normal" id="query">查&nbsp;询</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-table">
                <table id="tableElement" lay-filter="tableElement"></table>
            </div>
        </div>
    </div>
</div>
</div>

<script>
        layui.use(['table', 'form', 'jquery', 'element','layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var user;
            var alreadyRelate="";
            var options = {
                elem: "#tableElement",
                id: "modelReload",
                url: '/xuYiPoint/findPointNameList'
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,method: 'post'
                ,where: {
                   alreadyRelate : sessionStorage.getItem('alreadyRelate')
                }
                ,request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                loading: true,
/*                 page: {
                    count: "count",
                    limit: 10,
                    limits: [10, 20,30,40,50],
                    layout: ['prev', 'page', 'next', 'skip', 'limit', 'count'],
                    prev: "上一页",
                    next: "下一页",
                    groups: 5
                }, */
                cols: [[ //表头
                	{type: 'checkbox', fixed: 'left',width: '14%'},
                    {field: 'name', title: '点位名称',align:'center'}
                ]],
                done: function (res) {
                }
            };  
    		
    	table.render(options);
		//头工具栏事件
		  //头工具栏事件
		  table.on('toolbar(tableElement)', function(obj){
		    var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
		      case 'getCheckData':
		        var data = checkStatus.data;
		        console.info("---"+JSON.parse(JSON.stringify(data))[0]);
		        let a=data.map(items=>{
		        	return items.name
		        })

		        var ss=sessionStorage.getItem('test');
		        console.info("ss"+ss);
		        if(null!=ss&&""!=ss){
		        	a=ss+","+a;
		        }
		        sessionStorage.setItem('test', a);
		        
		        console.log("a"+a);
		        
		        layer.msg('关联成功！');
		        parent.tools.func1();
		        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				setTimeout(function(){
					parent.layer.close(index)
				},1500) //再执行关闭
		        
		        
		      break;
		    };
		  })

		//更新数据表
		$('#query').on('click', function () {
					
  	       			var regionNameText = $("#regionNameText").val();
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    
                    console.info(alreadyRelate);
                    //table.render(options);
                    
                    table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        regionNameText : regionNameText,
                        alreadyRelate : alreadyRelate
                    }
                });
                layer.close(index);
                
            });
           
            
            //身份识别
            $(document).ready(function () {
            	alreadyRelate=sessionStorage.getItem('alreadyRelate');
            	console.info(alreadyRelate);
            	sessionStorage.removeItem('test');
/*             	var regionNameText = $("#regionNameText").val();
  	       			
  	       			
   
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    
                    console.info(alreadyRelate);
                    //table.render(options);
                    
                    table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        regionNameText : regionNameText,
                        alreadyRelate : alreadyRelate
                    }
                }); 
                layer.close(index);*/
                
            });
           
           
    
    			$("#regionNameText").autocomplete({
                    source : function(request, response) {
                        var pointNameText = $("#regionNameText").val();
                        console.info(pointNameText);
                        var url = '/xuYiPoint/findPointNameList2';
                        var param = {
                            pointNameText : pointNameText
                        };
                        $.ajax({
                                type : 'post',
                                async : false,
                                url : url,
                                data : param,
                                success : function(json) {
                                    var data = json.data;
                                    source = [];
                                    for (var i = 0; i < data.length; i++) {
                                        source[i] = data[i].name;
                                    }
                                    console.log(source);
                                    response(source);
                                },
                                error : function() {
                                    layer.msg('系统异常，请联系管理员处理!');
                                }
                            }
                        );
                    },
                    messages : { //message设置不出现匹配关键字的结果
                        noResults: '',
                        results: function () {
                        }
                    },
    		});
        });
    </script>
    <script type="text/html" id="toolbarDemo">
  		<div class="layui-btn-container">
    		<button class="layui-btn layui-btn-sm" lay-event="getCheckData">点击关联点位</button>
  		</div>
	</script>
</body>
</html>